IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetAdvanceFundRequestProposalNumberList]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[GetAdvanceFundRequestProposalNumberList]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


--GetAdvanceFundRequestProposalNumberList 41359, '2005A000'

CREATE PROCEDURE [dbo].[GetAdvanceFundRequestProposalNumberList] 
(  
	@fwkDomainUserId	INT,
	@prefix	VARCHAR(20)
)  
AS 

SET NOCOUNT ON
BEGIN  
		    
			SELECT TOP 25 af.foldernumber 
			FROM  dbo.agragreement_fct af		
			INNER JOIN dbo.agragreementstatustype ast ON ast.id = af.statustypeid
			INNER JOIN dbo.agragreementstatustype ast1 ON ast1.Id = ast.mappedtostatus
			INNER JOIN dbo.UserResourceCache AS urc ON af.ResourceId = urc.ResourceId AND urc.resourcetypeID = 1 AND urc.fwkdomainuserid =  @fwkDomainUserId 					  
			WHERE ISNULL(af.fundid,'') ='' AND ast1.[name] IN ('Pending')
			AND foldernumber LIKE @prefix + '%'
			AND foldernumber NOT IN(SELECT propnumber FROM dbo.AdvanceFundRequest)
			

		  --PRINT(@OrderBy)

END



GO